package org.ourgrid.common.executor.config;

import java.io.File;

import org.ourgrid.worker.WorkerConstants;

/**
 * 
 * @author Carla Souza, carla.asouza@gmail.com
 *
 */
public class KVMExecutorConfiguration extends AbstractExecutorConfiguration {
	public static enum PROPERTIES {
		VM_NAME, 
		BEGIN_ALLOCATION_COMMAND, 
		START_VM_COMMAND, 
		STOP_VM_COMMAND, 
		CREATE_DEVICE_COMMAND,
		STATUS_VM_COMMAND, 
		RESOURCES_DIR, 
		GET_FILES_DEVICE_COMMAND,
		VM_PLAYPEN,
		VM_STORAGE, 
		VM_IMAGE_PATH,
		HOST_PLAYPEN, 
		HOST_STORAGE,
		UMOUNT_DEVICE_COMMAND,
		APP_STDOUT_FILE_NAME,
		APP_STDERROR_FILE_NAME,
		TERMINATION_FILE_NAME, KILL_COMMAND
	}

//	public KVMExecutorConfiguration(File rootDir, String[] propNames) {
//		super(rootDir, parseProperties());
//	}

	public KVMExecutorConfiguration(File rootDir) {
		super(rootDir, parseProperties());
	}

	public void setDefaultProperties() {
		 String startvmCmd = null;
		 String stopvmCmd = null;
		 String beginAllocationCmd = null;
		 String createDevCmd = null;
		 String vmStatusCmd = null;
		 String getFilesFromDevCmd = null;
		 this.properties.put(PROPERTIES.START_VM_COMMAND.toString(),
		 startvmCmd);
		 this.properties.put(PROPERTIES.STOP_VM_COMMAND.toString(),
		 stopvmCmd);
		 this.properties.put(PROPERTIES.BEGIN_ALLOCATION_COMMAND.toString(),
		 beginAllocationCmd);
		 this.properties.put(PROPERTIES.CREATE_DEVICE_COMMAND.toString(), createDevCmd);
		 this.properties.put(PROPERTIES.GET_FILES_DEVICE_COMMAND.toString(), getFilesFromDevCmd);
		 this.properties.put(PROPERTIES.STATUS_VM_COMMAND.toString(),
		 vmStatusCmd);

	}

	private static String[] parseProperties() {

		String[] properties = new String[PROPERTIES.values().length];

		for (int i = 0; i < PROPERTIES.values().length; i++) {
			properties[i] = WorkerConstants.PREFIX
					+ PROPERTIES.values()[i].toString();
		}

		return properties;
	}

}